import { _decorator, Component, Label, Node } from 'cc';
import { GLOBALVar } from './GlobalVar';
const { ccclass, property } = _decorator;

@ccclass('ShopManager')
export class ShopManager extends Component {
    @property({type: Node, tooltip: "商店页面"})
    private ShopPanel: Node | null = null;
    @property({type: Label, tooltip: "货币数量"})
    private CoinNumLabel: Label | null = null;
    start() {
        let Currency = GLOBALVar.getCurrency();
        this.CoinNumLabel.string = Currency.toString();
    }

    update(deltaTime: number) {
        
    }

    //商店
    onClickShopBtn() {
        this.ShopPanel.active = true;
    }
    
    onClickCloseShop() {
        this.ShopPanel.active = false;
    }

    onClickBuy(event: Event, p: string) {
        const PRICE = parseInt(p, 10);
        let Currency = GLOBALVar.getCurrency();
        if (PRICE > Currency) {
            alert("金币不足！")
            return;
        } else {
            GLOBALVar.setCurrency(Currency - PRICE);
            return;
        }
    }
}


